var express = require('express');
var router = express.Router();
var routerService = require('../service/routerService')  //router对应typerouters
var routersService = require('../service/routersService') //routers对应routers表单
var typesService = require('../service/typesService')

router.get('/query', async function (req, res, next) {
    let { type } = req.query
    let result = await routersService.query({ type });
    let result2 = await typesService.query({ typeid: { "$ne": 0 } })
    res.json({
        code: 200,
        data: result,
        typeList: result2
    })
});

//新增数据
router.post('/add', async function (req, res, next) {
    let { type, name, path, com } = req.body
    let result = await routersService.add({ type, name, path, com })
    res.json({
        code: 200,
        data: result
    })
});

//新增数据到typerouters
router.post('/typeroutersadd', async function (req, res, next) {
    let { list, typeid } = req.body
    // console.log(list, typeid);
    await routerService.delMany({ typeid })
    let result = await routerService.add(list)
    res.json({
        code: 200,
        data: result
    })
});

//查询数据到typerouters
router.get('/typeroutersquery', async function (req, res, next) {
    let typeid = req.query
    console.log(typeid);
    let result = await routerService.query(typeid)
    res.json({
        code: 200,
        data: result
    })
});

module.exports = router;
